<?php
		
		//$Id: cleanup.php 369 2009-03-01 10:15:56Z cameron.bracken $
		
		//Cleanup the output directory
		
		include("sandbox/www/vars.php");
		
		// this loop checks if there are more than $max_saved_runs
		// files in the $outdir,$logdir,$imgdir and deletes the oldest files if there 
		// are too many, otherwise display the name in the pulldown menu
		
		$dirs = array($outdir,$logdir,$imgdir);
		
		for($j=0; $j<=(count($dirs)-1); $j++){
			
			$i = 0;
			if($j==2){$mult = 2;}else{$mult = 1;}
			
			$filenames = array_reverse(glob("$dirs[$j]/*-*"));
			
			foreach ($filenames as $filename) {
				$i++;
				if($i > ($max_saved_runs * $mult)){
					//remove extra files
					unlink($filename);
				}
			}
		}

?>